package com.xm.zcf.action.action.categorySecond;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xm.zcf.domain.categorySecond.Categorysecond;
import com.xm.zcf.service.categorySecond.CategorySecondService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/3/15.
 */
@Controller
@Scope("prototype")
public class categorySecondAction extends ActionSupport implements ModelDriven<Categorysecond> {
    private Categorysecond model=new Categorysecond();
    private Integer csid;

    public Integer getCsid() {
        return csid;
    }

    public void setCsid(Integer csid) {
        this.csid = csid;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    private String message;

    public void setModel(Categorysecond model) {
        this.model = model;
    }

    @Resource
    private CategorySecondService categorySecondService;

    public String findSecondAll(){
        List<Categorysecond> categoryseconds=categorySecondService.findSecondAll();
        ActionContext.getContext().put("csList",categoryseconds);
        return "list";
    }
    public String  addUI(){
        return "addUI";
    }
    public String add(){
        categorySecondService.save(model);
        return "tolist";
    }
    public String editUI(){
        Categorysecond category=categorySecondService.findById(model.getCsid());
        ActionContext.getContext().getValueStack().push(category);
        return "editUI";
    }
    public String edit(){
        Categorysecond categorysecond=categorySecondService.findById(model.getCsid());
        categorysecond.setCsname(model.getCsname());
        categorySecondService.update(categorysecond);
        return "tolist";
    }
    public String delete(){
        Categorysecond category=categorySecondService.findById(model.getCsid());
        categorySecondService.deleteCategory(category);
        return "tolist";
    }

    @Override
    public Categorysecond getModel() {
        return model;
    }
}
